if defined? Rails
	if Rails::VERSION::MAJOR.to_i >= 3
		require "trifle/ruby/middleware/request_id"
		require "trifle/ruby/middleware/transaction_handler"

		module Trifle
			module Ruby
				module Integrations
					class Rails < ::Rails::Railtie

						initializer "trifle_ruby.use_middleware" do |app|
							if Trifle::Ruby::Engine.should_start_engine?(:rails)
              	puts "Loading Rails integration" unless Trifle::Ruby::Config.is_quiet?
								app.middleware.use Trifle::Ruby::Middleware::RequestId unless defined?(ActionDispatch::RequestId)
								app.middleware.use Trifle::Ruby::Middleware::TransactionHandler
							end
						end

						initializer "trifle_ruby.start_plugin" do |app|
							if Trifle::Ruby::Engine.should_start_engine?(:rails)
								Trifle::Ruby::Engine.subscribe(:rails)
							end
						end

					end
				end
			end
		end
	else
		puts "Only Rails 3.0 and newer is supported." unless Trifle::Ruby::Config.is_quiet?
	end
else
	puts "Only Rails framework is supported." unless Trifle::Ruby::Config.is_quiet?
end
